/*
 * author: downey
 * version: 1.0.0
 * git: http://git.kekuming.xin/downey/downey-canvas-charts.git
 */
import Bar from './bar'

export default class Bar2 extends Bar {

  /* 构造函数 */
  constructor(option = {}) {
    const parameter = {
      padding: [0, 0, 0, 0],
      sidesAxis: {
        show: false
      }
    };
    super({...option, ...parameter});
  }

  // 绘制面积
  drawXAxisBg() {
    this.ctx.beginPath();
    for (let i = 0; i <= this.numY; i++) {
      let y = this.ySpace * i;
      this.ctx.fillStyle = this.getColor('rgba(52, 214, 255, .06)');
      if (i < this.numY) this.ctx.fillRect(0, y, this.width, this.ySpace - 1);
    }
    this.ctx.closePath();
  }

  // 画装饰轴
  drawSpecial() {
    this.drawXAxisBg();

    const w = this.specialAxis.w || 8;

    // 底部分割线
    this.ctx.beginPath();
    this.ctx.save();
    const lineSplit = this.width / this.numX;
    const lineWidth = lineSplit * .8;
    const left = (lineSplit - lineWidth) / 2;
    for (let i = 0; i < this.xAxis.data.length; i++) {
      if (i > 0) this.ctx.translate(lineSplit, 0);
      this.ctx.moveTo(left, this.height + 10);
      this.ctx.lineTo(lineSplit - left, this.height + 10);
    }
    this.ctx.lineWidth = 1;
    this.ctx.strokeStyle = this.getColor('rgba(52, 214, 255, .5)');
    this.ctx.stroke();
    this.ctx.restore();
    this.ctx.closePath();

    // - 短线分割
    this.ctx.beginPath();
    this.ctx.lineWidth = 1;
    this.ctx.strokeStyle = this.getColor('rgba(254, 252, 242, .3)');
    for (let i = 0; i <= this.numY; i++) {
      let y = this.ySpace * i;
      // 左短线
      this.ctx.moveTo(0, y);
      this.ctx.lineTo(w, y);

      // 右短线
      this.ctx.moveTo(this.width - w, y);
      this.ctx.lineTo(this.width, y);
    }
    this.ctx.stroke();
    this.ctx.closePath();
  }

}

